import { Component, OnInit, Output, EventEmitter } from '@angular/core';

import { RemoveTableService } from '../../../../public/serve/remove-table/remove-table.service';
import { HintsService } from '../../../../public/serve/hints/hints.service';
import { CudTableService } from 'app/public/serve/cud-table/cud-table.service';
import { Service } from '../../../../server/server';
import { appProductUrl } from '../../../product.url';
import { product } from '../../../product.data';

declare var $: any;

@Component({
	selector: 'app-product-indexing-task-list-del',
	templateUrl: './product-indexing-task-list-del.component.html'
})
export class ProductIndexingTaskListDelComponent implements OnInit {

	one: any;
	ids: Array<any> = [];
	@Output() delEvent = new EventEmitter<void>();

	constructor(
        private server: Service,
		private request: CudTableService,
		public hintsService: HintsService
	) { }

	ngOnInit() {
	}

	setData(taskData) {
		this.ids.push(taskData.taskId + '');
	}

	/**
	 * 删除
	 */
	deleteTasks() {
		const params = {
			ids: this.ids,
			token: product.retrieval.token
		}
		this.request.postRequest(this.server.baseUrl +appProductUrl.deleteTasks, params).then(res => {
			this.hintsService.messages(res.message, res.result_code);
			this.ids = [];
			if (res.result_code == '0000') {
				this.delEvent.emit();
			}
		}).catch((err: any) => {
			//this.hintsService.messages('error', 'error');
		});
	}
}
